/*
package com.wgj.android.web;
import android.app.Activity;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.media.ThumbnailUtils;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.provider.MediaStore;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.util.Log;
import android.webkit.JavascriptInterface;

import com.alibaba.fastjson.JSONObject;
import com.jiaai.xui.XUI;
import com.jiaai.xui.jsbridge.CallBackFunction;
import com.jiaai.xui.utils.XBitmapUtils;
import com.jiaai.xui.utils.http.HttpCallBack;
import com.jiaai.xui.utils.http.ListHttpCallBack;
import com.jiaai.xui.utils.http.XHttp;
import com.jiaai.xui.utils.http.entity.VUpload;
import com.jiaai.xui.utils.share.ShareUtils;
import com.jiaai.xui.utils.share.entity.Share;
import com.jiaai.xui.view.XTakePhotosDialog;
import com.jiaai.xui.view.widget.XLoadingDialog;
import com.jiaai.xui.view.widget.XToast;
import com.just.agentweb.AgentWeb;
import com.wgj.android.R;
import com.wgj.android.dialog.AddressSelectDialog;
import com.wgj.android.dialog.CardShareDialog;
import com.wgj.android.dialog.SelectVideoDialog;
import com.wgj.android.dialog.ShareDiadlog;
import com.wgj.android.entity.Member;
import com.wgj.android.entity.SystemConfg;
import com.wgj.android.http.WGJAPI;
import com.wgj.android.ui.activity.ColumnLiveActivity;
import com.wgj.android.ui.activity.CreateCardActivity;
import com.wgj.android.ui.activity.TxActivity;
import com.wgj.android.ui.activity.VideoListActivity;
import com.wgj.android.ui.activity.VideoTuiGuangActivity;
import com.wgj.android.ui.activity.VideoTuiGuangActivity1;
import com.wgj.android.ui.activity.VideoUploadActivity;
import com.wgj.android.utils.BitmapUtil;
import com.wgj.android.utils.CacheUtils;
import com.wgj.android.utils.CommTools;
import com.wgj.android.utils.DownloadAppUtils;
import com.wgj.android.widget.imageselect.ImagePicker;
import com.wgj.android.widget.imageselect.cropper.CropImage;
import com.wgj.android.widget.imageselect.cropper.CropImageView;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static android.provider.MediaStore.Video.Thumbnails.MINI_KIND;
import static com.jiaai.xui.XUI.getSystemService;
import static com.wgj.android.utils.CommTools.LOCAL_VIDEO_REQUEST;

public class AndroidInterface {

    private Handler deliver = new Handler(Looper.getMainLooper());
    private AgentWeb agent;
    private Context context;
    private ImagePicker imagePicker;
    private ShareDiadlog shareDiadlog;
    private SystemConfg confg;
    private Share share;

    private String url;//分享
    private Handler handler = new Handler(){
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            //获取到图片后才显示
            shareDiadlog.show(((AppCompatActivity)context).getSupportFragmentManager(),"shareDialog");
        }
    };
    public AndroidInterface(AgentWeb agent, Context context) {
        this.agent = agent;
        this.context = context;
        imagePicker = new ImagePicker();
        // 设置标题
        imagePicker.setTitle("选择图片");
        // 设置是否裁剪图片
        imagePicker.setCropImage(true);


        confg=CacheUtils.getSystemConfig();

    }

    public  void onActivityResult(int requestCode, int resultCode, Intent data){

        imagePicker.onActivityResult((Activity) context, requestCode, resultCode, data);
        if(requestCode==CommTools.VIDEO_RECORD_REQUEST){
            if (null != data) {
                Uri uri = data.getData();
                if (uri == null) {
                    return;
                } else {
                    Cursor c = context.getContentResolver().query(uri,
                            new String[]{MediaStore.MediaColumns.DATA},
                            null, null, null);
                    if (c != null && c.moveToFirst()) {
                        String filPaths = c.getString(0);
                        Intent intent=new Intent(context, VideoUploadActivity.class);
                        Bundle bundle=new Bundle();
                        bundle.putString("video",filPaths);
                        bundle.putParcelable("thumb", ThumbnailUtils.createVideoThumbnail(filPaths,MINI_KIND));

                        intent.putExtras(bundle);
                        ( (AppCompatActivity)context).startActivity(intent);

                    }
                }
            }
        }else if(requestCode==LOCAL_VIDEO_REQUEST){
            if (resultCode == CommTools.LOCAL_VIDEO_RESULT && data != null) {
                String filPaths = data.getStringExtra("path");
                Intent intent=new Intent(context, VideoUploadActivity.class);
                Bundle bundle=new Bundle();
                bundle.putString("video",filPaths);
                intent.putExtras(bundle);
                ( (AppCompatActivity)context).startActivity(intent);
            }
        }
    }

    @JavascriptInterface
    public void selectImages() {
        new XTakePhotosDialog(context, R.style.dialog_setting).setTakePhotosListener(new XTakePhotosDialog.OnTakePhotosListener() {
            @Override
            public void onTakePictureClick() {
                imagePicker.startCamera((Activity) context, new ImagePicker.Callback() {
                    @Override
                    public void onPickImage(Uri imageUri) {


                    }
                    // 自定义裁剪配置
                    @Override public void cropConfig(CropImage.ActivityBuilder builder) {
                        builder
                                // 是否启动多点触摸
                                .setMultiTouchEnabled(false)
                                // 设置网格显示模式
                                .setGuidelines(CropImageView.Guidelines.OFF)
                                // 圆形/矩形
                                .setCropShape(CropImageView.CropShape.RECTANGLE)
                                // 调整裁剪后的图片最终大小
                                .setRequestedSize(360, 360)
                                // 宽高比
                                .setAspectRatio(1, 1);
                    }
                    @Override
                    public void onCropImage(Uri imageUri) {
                        uploadAvater(imageUri.getPath());

                    }
                });
            }

            @Override
            public void onChoosePictureClick() {
                imagePicker.startGallery((Activity) context, new ImagePicker.Callback() {
                    @Override
                    public void onPickImage(Uri imageUri) {
                    }
                    // 自定义裁剪配置
                    @Override public void cropConfig(CropImage.ActivityBuilder builder) {
                        builder
                                // 是否启动多点触摸
                                .setMultiTouchEnabled(false)
                                // 设置网格显示模式
                                .setGuidelines(CropImageView.Guidelines.OFF)
                                // 圆形/矩形
                                .setCropShape(CropImageView.CropShape.RECTANGLE)
                                // 调整裁剪后的图片最终大小
                                .setRequestedSize(360, 360)
                                // 宽高比
                                .setAspectRatio(1, 1);
                    }
                    @Override
                    public void onCropImage(Uri imageUri) {
                        uploadAvater(imageUri.getPath());
                    }
                });

            }
        }).show();

    }
    @JavascriptInterface
    public void showLoading(String messge) {
        if(TextUtils.isEmpty(messge)){
            XLoadingDialog.with(context).setMessage(messge).show();
        }else {
            XLoadingDialog.with(context).show();
        }

    }
    @JavascriptInterface
    public void hidLoadIng() {
        XLoadingDialog.with(context).hide();

    }
    @JavascriptInterface
    public void editCard(String cards) {
        Intent intent=new Intent(context, CreateCardActivity.class);
        Bundle bundle=new Bundle();
        bundle.putString("cards",cards);
        intent.putExtras(bundle);
        ( (AppCompatActivity)context) .startActivityForResult(intent,1000);
    }
    @JavascriptInterface
    public void shareCard(String cards) {
         CardShareDialog.getInstael(cards).show(((AppCompatActivity)context).getSupportFragmentManager(),"CardShareDialog");
    }


    @JavascriptInterface
    public void selectMap() {

    }

    */
/**
     * 上传视频
     *//*

    @JavascriptInterface
    public void upFilms() {
        new SelectVideoDialog(context,R.style.dialog_setting).setSelectVideosListener(new SelectVideoDialog.OnTakeVideosListener() {
            @Override
            public void onTakeVideosClick() {
                Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);// 创建一个请求视频的意图
                intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);// 设置视频的质量，值为0-1，
                intent.putExtra(MediaStore.EXTRA_DURATION_LIMIT, 2000);// 设置视频的录制长度，s为单位
                intent.putExtra(MediaStore.EXTRA_SIZE_LIMIT, 20 * 1024 * 1024L);// 设置视频文件大小，字节为单位
                ((Activity)context).startActivityForResult(intent, CommTools.VIDEO_RECORD_REQUEST);// 设置请求码，在onActivityResult()方法中接收结果
            }

            @Override
            public void onChooseVideosClick() {
                Intent intent = new Intent(context, VideoListActivity.class);
                ((Activity)context).startActivityForResult(intent, LOCAL_VIDEO_REQUEST);
            }
        }).show();
       // context.startActivity(new Intent(context, VideoUploadActivity.class));
    }
    @JavascriptInterface
    public void toPlay(String str) {
        context.startActivity(new Intent(context, VideoTuiGuangActivity1.class).putExtra("video",str));

    }
    @JavascriptInterface
    public void selectAddress() {

        AddressSelectDialog addressSelectDialog = new AddressSelectDialog();
        addressSelectDialog.show(((AppCompatActivity)context).getSupportFragmentManager(),"");
        addressSelectDialog.setCallBackFunction(new CallBackFunction() {
            @Override
            public void onCallBack(String s) {
                agent.getJsAccessEntrace().quickCallJs("window.onSelectAddress('"+s+"')");
            }
        });
    }
    @JavascriptInterface
    public  void toast(String message){
        if(message.indexOf("{")==0){
            JSONObject object=JSONObject.parseObject(message);
             switch (object.getString("type")){
                 case "error":
                     XToast.error(object.getString("msg"));
                     return;
                 case "success":
                     XToast.success(object.getString("success"));
                     return;
             }
        }else {
            XToast.success(message);
        }

    }
    @JavascriptInterface
    public void toOwn(String str) {
        context.startActivity(new Intent(context, VideoTuiGuangActivity.class).putExtra("video",str));
        //context.startActivity(new Intent(context, PlayerActivity.class).putExtra("video",str));
    }
    @JavascriptInterface
    public void playGeneralizeVideo(String str) {
        context.startActivity(new Intent(context, ColumnLiveActivity.class).putExtra("live",str));
    }
    @JavascriptInterface
    public void exit() {
        ((Activity)context).finish();
    }
    @JavascriptInterface
    public void shareGoods(final String goods) {
        JSONObject js = JSONObject.parseObject(goods);
        int goodsId= js.getIntValue("goodsId");
        String goodsImg=js.getString("goodsImg");
        String goodsIdDesc=js.getString("goodsDesc");
        String goodsTitle=js.getString("goodsTitle");
        String shopId=js.getString("shopId");


        shareDiadlog=new ShareDiadlog().setOnShareListener(new ShareDiadlog.OnShareListener() {
            @Override
            public void onShareQQ() {
                XToast.info("暂未开放");
            }

            @Override
            public void onShareWeiXin() {
                ShareUtils.shareWeiXin(context,share,confg.getWXAppId(),false);
                shareDiadlog.dismiss();
            }

            @Override
            public void onShareFriends() {
                ShareUtils.shareWeiXin(context,share,confg.getWXAppId(),true);
                shareDiadlog.dismiss();
            }

            @Override
            public void onShareSpaceBut() {
                XToast.info("暂未开放");
            }

            @Override
            public void onlinkButBut() {
                ClipboardManager cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
                cm.setPrimaryClip(ClipData.newPlainText(null, url));
                XToast.success("分享接连已复制到粘贴板,可以发送给朋友们了.");
            }
        });
        share=new Share();
        getGoodsBitmap(share,goodsImg);
        share.setThumUrl(goodsImg);
        share.setDescription(goodsIdDesc);
        share.setTitle(goodsTitle);
        //url=WGJAPI.WEB_URL+"/store/index.html#/shareGoods?userId="+ CacheUtils.getMember().getM_id()+"&goodsId="+goodsId;
        url=WGJAPI.WEB_URL+"/wx/shop/store/oauth?pId="+CacheUtils.getMember().getM_id()+"&shopId"+shopId+"&router=shareGoods&params="+goodsId;

        share.setWebUrl(url);
    }

    private void getGoodsBitmap(final Share share, final String goodsImg) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    share.setThumBitmap(BitmapUtil.getBitmap(goodsImg));
                } catch (IOException e) {
                    e.printStackTrace();
                    share.setThumBitmap(XBitmapUtils.getBitmapFromDrawable(XUI.getDrawable(R.mipmap.logo)));
                }finally {
                    handler.sendEmptyMessage(0);
                }
            }
        }).start();
    }

    */
/**
     * 佣金提现
     *//*

    @JavascriptInterface
    public void tixian() {
        //XXXWebActivity.getINT(context.getContext(),"file:///android_asset/index.html#/withdrawDeposit","佣金提现");
        context.startActivity(new Intent(context, TxActivity.class));
    }

    */
/**
     * 下载app
     *//*

    @JavascriptInterface
    public void downloadApp(String shopId) {
        //XXXWebActivity.getINT(context.getContext(),"file:///android_asset/index.html#/withdrawDeposit","佣金提现");
        //"http://download.fir.im/v2/app/install/5a47a5f2ca87a81bdd000115?download_token=b4ff070122cd373988714ec0922cb1d2&source=update"
       */
/* if(url.startsWith("http")){
            DownloadAppUtils.downloadForAutoInstall(context,url,"旺旺通商店","旺旺通发现新版本");
            XToast.info("正在下载");
        }*//*

        XHttp.obtain().post(WGJAPI.BASEURL + "common/shop/store/app/android?shopId=" + shopId, null, new HttpCallBack<String>() {
            @Override
            public void onSuccess(String s) {
                DownloadAppUtils.downloadForAutoInstall(context,url,"旺旺通商店","旺旺通");
            }

            @Override
            public void onFailed(int i, String s, boolean b) {
                XToast.error("失败");
            }
        });

    }

    */
/**
     *进入商店详情
     *//*

    @JavascriptInterface
    public void storeDetails(String json){
        JSONObject jsonObject=JSONObject.parseObject(json);
        String shopId=jsonObject.getString("shopId");
        String userId=jsonObject.getString("userId");
        XXXWebActivity.getINT(context,WGJAPI.WEB_URL+"/store/index.html#/goodsList?shopId="+shopId+"&ownUserId="+CacheUtils.getMember().getM_id()+"&userId="+userId,null);
    }
    */
/**
     *进入商品详情
     *//*

    @JavascriptInterface
    public void goodsDetails(String json){
        JSONObject jsonObject=JSONObject.parseObject(json);
        String shopId=jsonObject.getString("shopId");
        String goodsId=jsonObject.getString("goodsId");
        XXXWebActivity.getINT(context,WGJAPI.WEB_URL+"/store/index.html#/goodsDetails?goodsId="+goodsId+"&userId="+CacheUtils.getMember().getM_id()+"&shopId="+shopId,null);
    }
    private  void uploadAvater(String path){
        XLoadingDialog.with(context).show();
        Map<String,File> params=new HashMap<>();
        params.put("file",new File(path));
        XHttp.obtain().upload("wgj", params, new ListHttpCallBack<VUpload>() {
            @Override
            public void onSuccess(final List<VUpload> list) {
                XLoadingDialog.with(context).dismiss();
                String str =list.get(0).getFilePath();

                agent.getJsAccessEntrace().quickCallJs("window.onSelectImage('"+str.substring(1,str.length()-1)+"')");
                XToast.success("修改成功");
            }

            @Override
            public void onFailed(int i, String s, boolean b) {
                XToast.error("上传图片失败");
                XLoadingDialog.with(context).dismiss();
            }
        });
    }

}
*/
